/*
 * @Author: worldzb 
 * @Date: 2018-11-25 14:37:57 
 * @Last Modified by: worldzb
 * @Last Modified time: 2019-01-11 09:59:44
 */


class Runner{
    
    /**
     * 
     * @param {Generator } funcGenerator 
     */
    static generator(funcGenerator){
        //先执行第一步
        let snippet=funcGenerator.next();

        //snippet 为 { value : promise对象 , done:遍历是否结束}

        Runner.promise(snippet,funcGenerator);
    }

    //递归 遍历 funcGenerator 当中异步请求
    static promise(promise,funcGenerator){
        promise.value.then(function(res){
            let snippet=funcGenerator.next(res);//将第一步的值传出去
            if(!snippet.done){
                Runner.promise(snippet,funcGenerator);
            }
        })
    }
}

export default Runner;